# Maintianer: Santiago Torres-Arias <santiago@archlinux.org>
# Contributor: Stéphane Gaudreault <stephane@archlinux.org>

_pypiname=pyopencl
pkgbase=python-pyopencl
pkgname=('python-pyopencl' 'pyopencl-headers')
pkgver=2023.1
pkgrel=2
epoch=1
pkgdesc="A complete, object-oriented language binding of OpenCL to Python"
arch=('loong64' 'x86_64')
url="https://mathema.tician.de/software/pyopencl"
license=('MIT' 'Apache' 'BSD')
depends=('opencl-icd-loader' 'opencl-headers' 'mesa' 'boost-libs')
makedepends=('ctags' 'python-setuptools' 'python-mako' 'python-numpy' 'git'
             'pybind11')
checkdepends=('python-six' 'python-appdirs' 'python-pytest' 'python-pytools')
source=("git+https://github.com/inducer/pyopencl.git?signed#tag=v${pkgver}")
validpgpkeys=("900A958D9A0ACA58B1468F2471AA298BCA171145") # Andreas Ratchke
sha256sums=('SKIP')

build() {
    cd "pyopencl"
    git submodule init && git submodule update
    python3 ./configure.py --python-exe=python3 --cl-pretend-version=1.2 # --boost-python-libname=boost_python3
    make
}

check(){
    # INFO: to avoid a PLATFORM_NOT_FOUND_KHR error here, you would have to install
    # the driver of your specific video card in here
    # checkdepends+=('amdgpu')
    cd pyopencl
    PYTHONPATH="$PWD/build/lib.linux-$CARCH-3.10/" make tests
}

package_python-pyopencl() {
    depends+=('python' 'python-numpy' 'python-mako' 'python-pytools' 'pyopencl-headers' 'python-setuptools' 'python-cffi')

    cd pyopencl
    python3 setup.py install --prefix=/usr --root="${pkgdir}" --optimize=1 --skip-build

    rm -fr "${pkgdir}"/usr/include

    install -D -m644 LICENSE "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}

package_pyopencl-headers() {
    cd pyopencl
 
    install -Dm644 pyopencl/cl/*.cl -t "${pkgdir}"/usr/include/pyopencl 
    install -D -m644 LICENSE "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}
